package com.sc.service.impl;

import com.sc.controller.vo.*;
import com.sc.entity.Orders;
import com.sc.mapper.OrdersMapper;
import com.sc.service.OrdersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author 许一
 * @since 2023-12-08 11:38:15
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {
    @Resource
    private OrdersMapper ordersMapper;

    @Override
    public OrderLineChartVO getLineList(Long id) {
        OrderLineChartVO orderLineChartVO = ordersMapper.getLines(id);
        List<OrderLineChartDetiailVO> orderLineChartDetiailVOS = ordersMapper.getLineList(id);
        List<Long>  inboundOrdersList = new ArrayList<>();
        List<Long>  outboundOrdersList = new ArrayList<>();
        List<Long>  qualityInspectionOrdersList = new ArrayList<>();
        List<Long>  pickOrdersList = new ArrayList<>();
     if(orderLineChartDetiailVOS!=null &&orderLineChartDetiailVOS.size()!=0){
         for (int i=1;i<=24;i++){
             int k = 0;
             for (OrderLineChartDetiailVO orderLineChartDetiailVO : orderLineChartDetiailVOS){
                 if(i==orderLineChartDetiailVO.getHour()){
                     inboundOrdersList.add(orderLineChartDetiailVO.getInboundOrders());
                     outboundOrdersList.add(orderLineChartDetiailVO.getOutboundOrders());
                     qualityInspectionOrdersList.add(orderLineChartDetiailVO.getQualityInspectionOrders());
                     pickOrdersList.add(orderLineChartDetiailVO.getPickOrders());
                     k = 1;
                 }
             }
             if(k==0){
                 inboundOrdersList.add((long) 0);
                 outboundOrdersList.add((long)0);
                 qualityInspectionOrdersList.add((long)0);
                 pickOrdersList.add((long)0);
             }
         }
         if(outboundOrdersList != null){
             orderLineChartVO.setOutboundOrdersList(outboundOrdersList);
         }
         if(inboundOrdersList!=null){
             orderLineChartVO.setInboundOrdersList(inboundOrdersList);
         }
         if(outboundOrdersList != null){
             orderLineChartVO.setOutboundOrdersList(outboundOrdersList);
         }
         if(qualityInspectionOrdersList != null){
             orderLineChartVO.setQualityInspectionOrdersList(qualityInspectionOrdersList);

         }
         if(pickOrdersList!=null){
             orderLineChartVO.setPickOrdersList(pickOrdersList);
         }
     }
        return orderLineChartVO;
    }

    @Override
    public List<OrderPieChartVO> getPieList(Long id) {
        List<OrderPieChartVO> orderPieChartVOS = new ArrayList<>();
        OrderPieChartDetiailVO orderPieChartDetiailVO = ordersMapper.getPieList(id);

           if(orderPieChartDetiailVO != null){
               OrderPieChartVO orderPieChartVO1 = new OrderPieChartVO();
               orderPieChartVO1.setName("未开始");
               orderPieChartVO1.setValue(orderPieChartDetiailVO.getNotStart());
               OrderPieChartVO orderPieChartVO2 = new OrderPieChartVO();
               orderPieChartVO2.setName("进行中");
               orderPieChartVO2.setValue(orderPieChartDetiailVO.getOngoing());
               OrderPieChartVO orderPieChartVO3 = new OrderPieChartVO();
               orderPieChartVO3.setName("已完成");
               orderPieChartVO3.setValue(orderPieChartDetiailVO.getFinish());
               orderPieChartVOS.add(orderPieChartVO1);
               orderPieChartVOS.add(orderPieChartVO2);
               orderPieChartVOS.add(orderPieChartVO3);
           }
        return orderPieChartVOS;
    }

    @Override
    public OrderHistogramVO getHistogram(Long id) {
        OrderHistogramVO orderHistogramVO = new OrderHistogramVO();
        List<String> list1 = new ArrayList<>();
        List<Long> list2 = new ArrayList<>();
        List<Long> list3 = new ArrayList<>();
        List<Long> list4 = new ArrayList<>();
        List<OrderHistogramDetiailVO> orderHistogramDetiailVOS = ordersMapper.getHistogram(id);
        for(OrderHistogramDetiailVO orderHistogramDetiailVO : orderHistogramDetiailVOS){
            list1.add(orderHistogramDetiailVO.getName());
            list2.add(orderHistogramDetiailVO.getNotStart());
            list3.add(orderHistogramDetiailVO.getOngoing());
            list4.add(orderHistogramDetiailVO.getFinish());
        }
        orderHistogramVO.setNameList(list1);
        orderHistogramVO.setNotStartList(list2);
        orderHistogramVO.setOngoingList(list3);
        orderHistogramVO.setFinishList(list4);
        return orderHistogramVO;
    }

    @Override
    public OrderSumVO getSum(Long id) {
        return ordersMapper.getSum(id);
    }

    @Override
    public List<OrderOutboundRateVO>  getOutboundRate(Long id) {
        return ordersMapper.getOutboundRate(id);
    }

    @Override
    public List<OrderVolumeVO> getWorkload(Long id) {
        return ordersMapper.getWorkload(id);
    }
}
